package middle;

import java.util.ArrayList;
import java.util.List;

public class Solution_199 {

    private final List<Integer> list = new ArrayList<>();

    public List<Integer> rightSideView(TreeNode root) {
        list.clear();;
        dps(root, 0);
        return list;
    }

    private void dps(TreeNode node, int level) {
        if (node == null) {
            return;
        }
        if (level >= list.size()) {
            list.add(node.val);
        }
        dps(node.right, level + 1);
        dps(node.left, level + 1);
    }

    static class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {         this.val = val;
          this.left = left;
          this.right = right;
      }
  }
}
